<?php

namespace App\Http\Controllers\Rent\Product;

use App\Http\Controllers\ShopController;
use App\Models\Product\Lease as LeaseModel;

class OrderController extends ShopController
{
    public function index()
    {
        $page = request('page',1);
        $limit = request('limit',10);
        $status = request('status',0);
        $business = request()->get('business');

        // 偏移量
        $start = ($page - 1) * $limit;

        // 条件数组
        $where[] = ['busid','=',$business['id']];

        if($status)
        {
            $where[] = ['status','=',$status];
        }

        $count = LeaseModel::with('product')->where($where)->count();

        $list = LeaseModel::with('product')->where($where)->OrderBy('createtime','desc')->offset($start)->limit($limit)->get();

        if($count > 0)
        {
            return $this->success('查询成功',['count' => $count,'list' => $list]);
        }else{
            return $this->error('暂无订单');
        }
    }
}
